unit SortUnit;

interface

uses common;

type
  Sort = class
    runNumber, number : integer;
    constructor Create;
    function step(var arr : array of integer) : boolean;
  end;

implementation

{ Sort }

constructor Sort.Create;
begin
  runNumber := 0;
  number := 0;
end;

function Sort.step(var arr: array of integer) : boolean;
var t : integer;
begin
  if (arr[number] > arr[number+1]) then
  begin
    t := arr[number];
    arr[number] := arr[number+1];
    arr[number+1] := t;
  end;
  inc(number);

  if (number >= N-runNumber-1) then
  begin
    inc(runNumber);
    number := 0;
    if (runNumber >= N) then
    begin
      step := false;
      exit;
    end;
  end;
  step := true;
end;

end.
